#!/bin/bash
#function:install nginx 1.10.1
#auther:smile
#email:liuliqiao@idealsee.cn
#date:2016.8.25
#version:1.0

#file
nginx_file_name="nginx-1.10.1.tar.gz"
ngx_http_auth_file_name="tip.tar.gz"
nginx_upload_module_file_name="nginx-upload-module-2.2.zip"
nginx_upstream_fair_file_name="nginx-upstream-fair-master.zip"

#var
nginx_work_dir="/opt/nginx_work"
nginx_install_dir="/opt/nginx_work/nginx-1.10.1"
nginx_conf_name="nginx.conf"
nginx_target_dir="/usr/local/nginx-1.10.1"

#install depend packages
apt-get install  gcc libperl-dev zlib1g-dev  libpcre3-dev libssl-dev unzip -y -qq
#wget packages
wget -c http://10.0.1.244/src_static/$nginx_file_name -P $nginx_work_dir
wget -c http://10.0.1.244/src_static/$ngx_http_auth_file_name -P $nginx_work_dir
wget -c http://10.0.1.244/src_static/$nginx_upload_module_file_name -P $nginx_work_dir
wget -c http://10.0.1.244/src_static/$nginx_upstream_fair_file_name -P $nginx_work_dir
#tar packages
[ ! -d /opt/nginx_work ] && exit ;
cd $nginx_work_dir && tar xf nginx-1.10.1.tar.gz -C $nginx_work_dir
tar xf tip.tar.gz -C $nginx_work_dir
unzip nginx-upload-module-2.2.zip -d $nginx_work_dir
unzip nginx-upstream-fair-master.zip -d $nginx_work_dir && mv $nginx_work_dir/nginx-upstream-fair-master $nginx_work_dir/nginx-upstream-fair

#install nginx
cd $nginx_install_dir && ./configure --prefix=$nginx_target_dir --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-mail \
--with-mail_ssl_module --with-poll_module --with-http_stub_status_module --with-http_perl_module \
--add-module=$nginx_work_dir/nginx-upstream-fair --add-module=$nginx_work_dir/nginx-upload-module-2.2 \
--add-module=$nginx_work_dir/ngx_http_auth_request_module-662785733552
make && make install

#wget conf or write conf
# wget -c http://10.0.1.244/software/conf/$nginx_conf_name -P /etc

#start nginx
#cp -f $nginx_install_dir/conf/mime.types /etc/mime.types
#[ $? == "0" ] && /usr/local/nginx/sbin/nginx -c /etc/$nginx_conf_name
#[ $? == "0" ] && echo -e "\033[31m nginx-server is running \033[0m"

#del tar

